package us.pigsoft.client;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.util.ArrayList;

public class Player extends Mob {

	public Player(GuiGame game, Dimension bounds) {
		super(game, bounds);
		
		x = -originX;
		y = -originY;
		
		// Create another sexy triangle 
		Polygon innerSight = new Polygon();
		innerSight.addPoint((int)x+7, (int)y+32);
		innerSight.addPoint((int)x+(size.width/2), (int)y-10);
		innerSight.addPoint((int)(x + size.width - 7), (int)(y+32));
		innerSight.addPoint((int)(x + size.width/2), (int)(y+25));
		shapes.add(innerSight);
		shapeColors.add(Color.BLUE);
		
		x = game.size.getWidth()/2;
		y = game.size.getHeight()/2;
	}
	
	

	@Override
	public void draw(Graphics2D g) {
		// TODO Auto-generated method stub
		super.draw(g);
	}



	@Override
	public void update() {
		if(InputHandler.getMousePress(true) == 0)
		{
			attack();
		}
		
		if(InputHandler.getKey('a')) {
			angle -= 0.15;
		} 
		
		if(InputHandler.getKey('d')) {
			angle += 0.15;
		}
		
		if(InputHandler.getKey('w')) {
			speed += acceleration;
			if(speed > maxSpeed)
				speed = maxSpeed;
			
		} else if(InputHandler.getKey('s')) {
			speed -= acceleration;
			if(speed <= -maxSpeed)
				speed = -maxSpeed;
			//x -= Math.cos(angle - Math.PI/2.0) * speed;
			//y -= Math.sin(angle - Math.PI/2.0) * speed;
		} else {
			if(speed > 0) {
				speed -= coastRate;
				if(speed <= 0)
					speed = 0;
			} else if(speed < 0) {
				speed += coastRate;
				if(speed >= 0)
					speed = 0;
			}
			
		}
		
		x += Math.cos(angle - Math.PI/2.0) * speed;
		y += Math.sin(angle - Math.PI/2.0) * speed;
	}

	@Override
	public void onDeath() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void attack() {
		// Create a bullet
		new Projectile(this);
	}
}
